﻿Option Explicit On 
Option Strict Off

Imports System.Windows.Forms

''' -----------------------------------------------------------------------------
' Trungdq viet de thiet lap readonly cho cac controls
'27-04-06
Public Class CControl_read_only

#Region "Public interface"
    Public Shared Sub SetReadOnly(ByVal i_control As System.Windows.Forms.Control)
        Try
            Dim v_Control As System.Windows.Forms.Control
            With i_control
                For Each v_Control In .Controls
                    'Dat thuoc tinh cho cac Child controls
                    SetReadOnly(v_Control)
                    'Neu la textbox dat readonly = true
                    If TypeOf v_Control Is TextBox Then
                        Dim v_ctrl As TextBox = v_Control
                        v_ctrl.ReadOnly = True
                        'Neu khong la textbox dat Enable = false
                    ElseIf TypeOf v_Control Is CheckBox Then
                        Dim v_ctrl As CheckBox = v_Control
                        v_Control.Enabled = False
                        'Neu khong la textbox dat Enable = false
                    ElseIf TypeOf v_Control Is RadioButton Then
                        Dim v_ctrl As RadioButton = v_Control
                        v_Control.Enabled = False
                        'Neu khong la textbox dat Enable = false
                    ElseIf TypeOf v_Control Is DateTimePicker Then
                        Dim v_ctrl As DateTimePicker = v_Control
                        v_Control.Enabled = False
                        'Neu khong la textbox dat Enable = false
                    ElseIf TypeOf v_Control Is ComboBox Then
                        Dim v_ctrl As ComboBox = v_Control
                        v_Control.Enabled = False
                    End If
                Next
            End With
        Catch exp As Exception
            MessageBox.Show(exp.Message)
        End Try
    End Sub
    Public Shared Sub SetWriteAble(ByVal i_control As System.Windows.Forms.Control)
        Try
            Dim v_Control As System.Windows.Forms.Control
            With i_control
                For Each v_Control In .Controls
                    'Dat thuoc tinh cho cac Child controls
                    SetWriteAble(v_Control)
                    'Neu la textbox dat readonly = false
                    If TypeOf v_Control Is TextBox Then
                        Dim v_ctrl As TextBox = v_Control
                        v_ctrl.ReadOnly = False
                        'Neu khong la textbox dat Enable = true
                    ElseIf TypeOf v_Control Is CheckBox Then
                        Dim v_ctrl As CheckBox = v_Control
                        v_Control.Enabled = True
                        'Neu khong la textbox dat Enable = false
                    ElseIf TypeOf v_Control Is RadioButton Then
                        Dim v_ctrl As RadioButton = v_Control
                        v_Control.Enabled = True
                        'Neu khong la textbox dat Enable = false
                    ElseIf TypeOf v_Control Is DateTimePicker Then
                        Dim v_ctrl As DateTimePicker = v_Control
                        v_Control.Enabled = True
                        'Neu khong la textbox dat Enable = false
                    ElseIf TypeOf v_Control Is ComboBox Then
                        Dim v_ctrl As ComboBox = v_Control
                        v_Control.Enabled = True
                    End If
                Next
            End With
        Catch exp As Exception
            MessageBox.Show(exp.Message)
        End Try
    End Sub
#End Region
End Class
